package com.ly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ly.handler.BusinessException;
import com.ly.response.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ly.mapper.UserMapper;
import com.ly.entity.User;
import com.ly.service.UserService;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private  UserMapper userMapper;

    @Override
    public boolean checkUser(String name) {
        LambdaQueryWrapper<User> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(User::getUserCode,name);
        User user = this.baseMapper.selectOne(wrapper);
       if(user!=null){
           //用户不为空说明已经存在了，则抛出异常，告诉用户不能注册
           throw  new BusinessException(ResultCode.USER_ACCOUNT_ALREADY_EXIST.getCode(),ResultCode.USER_ACCOUNT_ALREADY_EXIST.getMessage());
       }
       return true;
    }
}



